//
//  AdressAndSortingView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/19.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "AdressAndSortingView.h"
#import "TitleListTableViewCell.h"

@interface AdressAndSortingView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView * screeTableView;
@property (nonatomic,assign)ListType listType;
@property (nonatomic,copy) NSArray * leftDataSource;
@end
@implementation AdressAndSortingView


-(id)initWithFrame:(CGRect)aFrame theTableListType:(ListType)l_type inSuperView:(UIView *)aSuperView{
    if (self = [super initWithFrame:aFrame inSuperView:aSuperView]) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];//145
        if (l_type == ListType_AllAdress) {
            self.leftDataSource = @[@"北京",@"上海",@"天津",@"深圳"];
        }else{
            self.leftDataSource = @[@"综合排序",@"价格最低",@"价格最高",@"最新上架",@"最早上架"];
        }
        self.screeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.1) style:UITableViewStylePlain];
        //
        self.screeTableView.delegate = self;
        self.screeTableView.dataSource = self;
        self.screeTableView.backgroundColor = [UIColor whiteColor];
        self.screeTableView.showsVerticalScrollIndicator = NO;
        self.screeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.screeTableView.estimatedRowHeight = 0;
        self.screeTableView.estimatedSectionHeaderHeight = 0;
        self.screeTableView.estimatedSectionFooterHeight = 0;
        self.screeTableView.tableFooterView = [[UIView alloc] init];
        self.screeTableView.rowHeight = kHeightProportion_In_iPhoneTriploid(44);
        [self addSubview:self.screeTableView];
        [UIView animateWithDuration:0.25 animations:^{
            self.screeTableView.height = self.leftDataSource.count * kHeightProportion_In_iPhoneTriploid(44);
        }];
        //
        UITapGestureRecognizer * tap_hider = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap_Hider:)];
        tap_hider.numberOfTouchesRequired = 1;
        tap_hider.numberOfTapsRequired = 1;
        [self addGestureRecognizer:tap_hider];
        self.userInteractionEnabled = YES;
    }
    return self;
}

-(void)tap_Hider:(UITapGestureRecognizer *)tag{
    [self dissmiss];
}

#pragma mark  ----- UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.leftDataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TitleListTableViewCell * cell = [TitleListTableViewCell cellWithTableView:tableView];
    cell.leftTitleStr = self.leftDataSource[indexPath.row];
    [cell setSepartionLineWith:lineModel_Half];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self dissmiss];
}
- (void)dissmiss {
    [self removeFromSuperview];
}

@end
